package com.shop.storage.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.shop.common.core.web.page.TableDataInfo;
import com.shop.storage.vo.request.PurchaseAddRequest;
import com.shop.storage.vo.request.PurchaseRequest;
import com.shop.storage.vo.response.PurchaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shop.common.log.annotation.Log;
import com.shop.common.log.enums.BusinessType;
import com.shop.common.security.annotation.RequiresPermissions;
import com.shop.storage.domain.WmsPurchase;
import com.shop.storage.service.IWmsPurchaseService;
import com.shop.common.core.web.controller.BaseController;
import com.shop.common.core.domain.Result;
import com.shop.common.core.utils.poi.ExcelUtil;


/**
 * 采购信息Controller
 *
 * @author czb
 * @date 2024-06-26
 */
@RestController
@RequestMapping("/purchase")
public class WmsPurchaseController extends BaseController
{
    @Autowired
    private IWmsPurchaseService wmsPurchaseService;

/**
 * 查询采购信息列表
 */
@RequiresPermissions("storage:purchase:list")
@GetMapping("/list")
    public Result list(WmsPurchase wmsPurchase)
    {
        startPage();
        List<WmsPurchase> list = wmsPurchaseService.selectWmsPurchaseList(wmsPurchase);
        return getDataTable(list);
    }

    /**
     * 导出采购信息列表
     */
    @RequiresPermissions("storage:purchase:export")
    @Log(title = "采购信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WmsPurchase wmsPurchase)
    {
        List<WmsPurchase> list = wmsPurchaseService.selectWmsPurchaseList(wmsPurchase);
        ExcelUtil<WmsPurchase> util = new ExcelUtil<WmsPurchase>(WmsPurchase.class);
        util.exportExcel(response, list, "采购信息数据");
    }

    /**
     * 获取采购信息详细信息
     */
    @RequiresPermissions("storage:purchase:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id)
    {
        return success(wmsPurchaseService.selectWmsPurchaseById(id));
    }

    /**
     * 新增采购信息
     */
    @RequiresPermissions("storage:purchase:add")
    @Log(title = "采购信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody WmsPurchase wmsPurchase)
    {
        return toAjax(wmsPurchaseService.insertWmsPurchase(wmsPurchase));
    }

    /**
     * 修改采购信息
     */
    @RequiresPermissions("storage:purchase:edit")
    @Log(title = "采购信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody WmsPurchase wmsPurchase)
    {
        return toAjax(wmsPurchaseService.updateWmsPurchase(wmsPurchase));
    }

    /**
     * 删除采购信息
     */
    @RequiresPermissions("storage:purchase:remove")
    @Log(title = "采购信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids)
    {
        return toAjax(wmsPurchaseService.deleteWmsPurchaseByIds(ids));
    }

    /**
     * 组合查询
     */

    @PostMapping("/purchaseList")
    public Result<TableDataInfo> purchaseList(@RequestBody PurchaseRequest purchaseDetailDto){
        List<PurchaseResponse> listDetailList =  wmsPurchaseService.purchaseList(purchaseDetailDto);
        return getDataTable(listDetailList);
    }

    /**
     * 添加采购详情
     */
    @PostMapping("/purchaseAdd")
    public Result purchaseAdd(@RequestBody PurchaseAddRequest purchaseAddRequest){
        return toAjax(wmsPurchaseService.purchaseAdd(purchaseAddRequest));

    }
}
